package mobi.hami.huapin.service.impl;

import mobi.hami.huapin.dao.PoiInfoMapper;
import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.PoiInfo;
import mobi.hami.huapin.service.PoiInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Create by 小峰 on 2018/8/23.
 */
@Service
public class PoiInfoServiceImpl implements PoiInfoService {

    @Autowired
    private PoiInfoMapper poiInfoMapper;

    @Override
    public int save(PoiInfo poiInfo) {
        poiInfo.setCity_code(poiInfo.getAdcode().substring(0, 4) + "00");
        poiInfo.setProvince_code(poiInfo.getAdcode().substring(0, 2) + "0000");
        List<String> list = poiInfoMapper.getPOINameByadcodes(poiInfo.getAdcode() + "," + poiInfo.getCity_code() + "," + poiInfo.getProvince_code());
        if (list != null && list.size() > 0) {
            poiInfo.setProvince_name(list.get(0));
            poiInfo.setCity_name(list.get(1));
            if (list.size() > 2)
                poiInfo.setArea_name(list.get(2));
        }
        return poiInfoMapper.insertSelective(poiInfo);
    }

    @Override
    public PoiInfo getOney(String id) {
        PoiInfo poiInfo = poiInfoMapper.selectByPrimaryKey(id);
        if (poiInfo != null) {
            String areaInfo = poiInfo.getCity_name() == null ? "" : poiInfo.getCity_name()
                    + poiInfo.getArea_name() == null ? "" : poiInfo.getArea_name();
            poiInfo.setCity_name(areaInfo);
        }
        return poiInfo;
    }
}
